import requests
import json
API_KEY = '72dbad85b92ab0560416334ba47f74ed'


class YunPian(object):
    def __init__(self, api_key):
        self.api_key = api_key
        self.single_send_url = 'https://sms.yunpian.com/v2/sms/single_send.json'
        self.add_template_url = 'https://sms.yunpian.com/v2/tpl/add.json'

    def send_sms(self, code, mobile):
        parmas = {
            'apikey': API_KEY,
            'mobile': mobile,
            'text': "{code}".format(code=code),
        }
        # response = requests.post(self.single_send_url, data=parmas)
        # re_dict = json.loads(response.text)
        re_dict = {
            'code': 0,
            'msg': "发送成功"
        }
        return re_dict

    def add_template(self):
        data = {
            'apikey': self.api_key,
            'tpl_content': '【生鲜超市】您的验证码是#code#'
        }
        response = requests.post(self.add_template_url, data=data)
        re_dict = json.loads(response.text)
        return 0


if __name__ == "__main__":
    yunpian = YunPian(API_KEY)
    # yunpian.send_sms("2123", '15659781161')
    # yunpian.add_template()
